//Man H. Vu
//CS 362: Software Engineering II
//Random Testing Adventurer Card
#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

void zzzadventurercardplay(int drawntreasure, int currentPlayer, int cardDrawn,
		int temphand[MAX_HAND], int z, struct gameState* state);

void testAdventurer(){
	int count = 1;
	while(1){
		struct gameState * game = newGame();
		int cards[10] = {adventurer, gardens, embargo, village, minion, mine, ambassador,
			sea_hag, tribute, smithy};
		int players = 2 + rand()%3;				//game between 2 players and max 4
		initializeGame(players, cards, rand(), game);
		int player_no = rand()%players;
		int handCount = rand()%MAX_HAND;
		int temphand[MAX_HAND];
		int i;
		int drawn = rand()%26;
		game->deckCount[player_no] = rand()%(MAX_DECK - handCount);
		game->handCount[player_no] = handCount;
		game->discardCount[player_no] = MAX_DECK - game->deckCount[player_no];

		//randomize player_no's deck
		for (i = 0; i < game->deckCount[player_no]; i++){
			game->deck[player_no][i] = rand()%26;
		}
		//randomize player_no's hand
		for (i = 0; i < game->handCount[player_no]; i++){
			game->hand[player_no][i] = rand()%26;
		}
		//randomize player_no's discard pile
		for (i = 0; i < game->handCount[player_no]; i++){
			game->discard[player_no][i] = rand()%26;
		}
		zzzadventurercardplay(0, player_no, drawn, temphand, 0, game);
		if ((game->handCount[player_no] == handCount + 2) &&
				(game->hand[player_no][game->handCount[player_no] - 1] ==
					copper || silver || gold) &&
				(game->hand[player_no][game->handCount[player_no] - 2] ==
					copper || silver || gold))
			printf("%d PASS: Drew 2 treasure cards.\n", count);
		else {
			printf("%d FAIL: Treasure cards was not drawn properly\n", count);
			break;
		}
		count++;
	}
}

int main(){
	srand(time(NULL));
	testAdventurer();
	return 0;
}
